package com.bw.exam.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bw.exam.mapper.TypeTemplateMapper;
import com.bw.exam.pojo.TypeTemplate;
import com.bw.exam.service.TypeTemplateService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author liuzhiping
* @description 针对表【tb_type_template】的数据库操作Service实现
* @createDate 2024-08-15 11:26:34
*/
@Service
public class TypeTemplateServiceImpl extends ServiceImpl<TypeTemplateMapper, TypeTemplate>
    implements TypeTemplateService{


    @Override
    public TypeTemplate getByIdOptions(Long id) {
        return this.getById(id);
    }

       /* @Override
        public TypeTemplate getByIdOptions(Long id) {
            TypeTemplate typeTemplate = this.getById(id);
            // [{"id":27,"text":"网络"},{"id":32,"text":"机身内存"}]
            String specIds = typeTemplate.getSpecIds();
            // 转成数组
            List<Spec> specList = JSON.parseArray(specIds, Spec.class);
            // 循环数组获取id
            for (Spec spec : specList) {
                Long specId = spec.getId();
                // 根据id去查询options表数据
                LambdaQueryWrapper<SpecificationOption> querWapper = new LambdaQueryWrapper<SpecificationOption>();
                querWapper.eq(SpecificationOption::getSpecId,specId);
                List<SpecificationOption> specificationOptions = specificationOptionMapper.selectList(querWapper);
                // 把options表数据放入到数组当中
                spec.setOptionList(specificationOptions);
            }

            // 最周把处理好的数据，转换成json字符串，重新赋值给specIds
            typeTemplate.setSpecIds(JSON.toJSONString(specList));
            // 返回前台处理
            return typeTemplate;
        }*/

}




